package com.java.main.gis;

/**
 * @Description
 * @Author 顾志杰
 * @Date 2021/9/6 08:13
 */
public class GisTest {

    public static void main(String[] args) {
        //116.405994,39.914271

        //116.442788,39.912943
        System.out.println(Distance(126.654842,45.761189,126.65415,45.761547));

    }


    public static double Distance(double long1, double lat1, double long2,
                                  double lat2) {
        double a, b, R;
        R = 6378137; // 地球半径
        lat1 = lat1 * Math.PI / 180.0;
        lat2 = lat2 * Math.PI / 180.0;
        a = lat1 - lat2;
        b = (long1 - long2) * Math.PI / 180.0;
        double d;
        double sa2, sb2;
        sa2 = Math.sin(a / 2.0);
        sb2 = Math.sin(b / 2.0);
        d = 2
                * R
                * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1)
                * Math.cos(lat2) * sb2 * sb2));
        return d;
    }
}
